﻿using Jobs.Common;
using System;
using System.Collections.Generic;

namespace MyJob
{
    public class MyJobConfig
    {

        /// <summary>
        /// 数据库连接
        /// </summary>
        public string connStr { get; set; }

        public MyJobConfig()
        {
            SetDefaultValue(this);
        }

        

        private static string path = AppDomain.CurrentDomain.BaseDirectory + "\\Config\\MyJobConfig.json";

        private static JSONConfig<MyJobConfig> _jSONConfig;

        public static MyJobConfig _config;

        private static void SetDefaultValue(MyJobConfig set)
        {
            set.connStr = "Data Source=10.47.22.102; database=cwbase001; User ID=lr01; Password=Aa123456";
        }

        public void Save()
        {
            _jSONConfig.Save();
        }

        public static MyJobConfig Default
        {
            get
            {
                if (_jSONConfig == null)
                {
                    _jSONConfig = new JSONConfig<MyJobConfig>(path);
                    //如果文件不存在则设置默认值
                    if (_jSONConfig.IsFileExists == false)
                    {
                        SetDefaultValue(_jSONConfig.Default);
                        _jSONConfig.Save();
                    }
                    _config = _jSONConfig.Default;
                }
                return _config;
            }
        }
    }

    

}
